<template>
  <div class="contain">
    <!-- 搜索 -->
    <el-form :model="query" ref="queryForm" :inline="true" class="top-search" label-position="left">
      <el-form-item label="标题" prop="sender">
        <el-input v-model="query.title" placeholder="请输入" clearable />
      </el-form-item>
      <el-form-item label=" ">
        <el-button type="primary" @click="getList()">查询</el-button>
      </el-form-item>
    </el-form>
    <!-- 操作菜单 -->
    <div class="mid-action">
      <div>
        <el-button type="primary" size="mini" @click="creatItem('creat')">添加</el-button>
      </div>
    </div>
    <!-- 表格列表 -->
    <el-table v-loading="loading" :data="list">
      <el-table-column label="ID" align="center" prop="id" width="100px" />
      <el-table-column label="面积(m²)" align="center" prop="scope"></el-table-column>
      <el-table-column label="创建时间" align="center" prop="createTime" />
      <el-table-column label="操作" align="center" width="180">
        <template slot-scope="scope">
          <el-button size="mini" type="text" @click="creatItem('edit', scope.row)">编辑</el-button>
          <el-button v-hasPermi="['enterpriseWechat:edit']" size="mini" type="text" @click="deleteItem(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="query.pageNum"
      :limit.sync="query.pageSize"
      @pagination="getList()"
    />
    <!-- 编辑表单 -->
    <el-dialog :title="formTtile == 'creat' ? '添加' : '编辑'" :visible.sync="editFormShow">
      <el-form class="edit_form" :model="form" ref="form" label-width="100px" label-position="right">
        <el-form-item label="房源面积范围" prop="scope">
          <el-input class="input" v-model="form.scope" placeholder="请输入" clearable  />平米
        </el-form-item>
        <el-form-item label=" ">
          <el-button type="primary" @click="submit()">提交</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import { getParkAreaList, creatParkArea, updateParkArea, deleteParkArea } from "@/api/eh-api";
import { getToken } from "@/utils/auth";
export default {
  data() {
    return {
        uploadUrl:'',
        // 遮罩层
        loading: false,
        // 总条数
        total: 0,
        // 查询参数
        query: {
            pageNum: 1,
            pageSize: 10,
            title: undefined,
        },
        list:[],
        editFormShow:false,
        formTtile:'creat',
        form:{
            "scope": "",
        },
        //荣誉资质
        honorCertificationList:[],
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /**
     * 获取列表
     */
    getList() {
      this.loading = true;
      getParkAreaList(this.query)
        .then(({ rows, total }) => {
          this.list = rows;
          this.total = parseInt(total);
          this.loading = false;
          this.ids = [];
        })
        .catch(() => {
          this.loading = false;
        });
    },

    /**
     * 添加
     */
    creatItem:function(title,item) {
      this.formTtile = title
      this.editFormShow = true
      if( title == 'edit' ){
        this.form = item
      }else{
        this.form = {}
      }
    },
    /**
     * 提交表单
     */
    submit:function(params) {
        console.log( this.form )
        if( this.formTtile == 'creat' ){
          creatParkArea(this.form).then( res => {
            if( res.code == 200 ){
              this.$message({
                message: '添加成功',
                type: 'success'
              });
              this.getList();
            }else{
              this.$message.error(res.msg);
            }
          })
        }else{
          updateParkArea(this.form).then( res => {
              if( res.code == 200 ){
                this.$message({
                  message: '编辑成功',
                  type: 'success'
                });
                this.getList();
              }else{
                this.$message.error(res.msg);
              }
            })
        }
        this.editFormShow = false
    },
    /**
     * 删除
     */
    deleteItem:function(rows) {
        console.log(rows)
        deleteParkArea({
          id:rows.id
        }).then( res => {
            if( res.code == 200 ){
              this.$message({
                message: '删除成功',
                type: 'success'
              });
              this.getList();
            }else{
              this.$message.error(res.msg);
            }
        })
    },
    /**
     * 统一路由
     */
    route(row) {
      console.log(row)
      this.$router.push({ path: 'creat', query: { id:row.id } })
    },
  },
};
</script>

<style lang="scss" scoped>
.mid-action {
  display: flex;
  justify-content: space-between;
  margin: 10px 0;
  align-items: center;
  .total {
    background-color: rgba(65, 133, 244, 0.1);
    border: 1px solid rgba(65, 133, 244, 0.2);
    border-radius: 3px;
    font-size: 14px;
    min-height: 32px;
    line-height: 32px;
    padding: 0 12px;
    color: #606266;
  }
  .num {
    color: #00f;
  }
}
.thumbnail {
  width: 160px;
  height: 80px;
}
.input{
  width: 80%;
}

/**头像 */
.avatar-uploader /deep/.el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
}
.avatar-uploader /deep/.el-upload:hover {
    border-color: #409EFF;
}
.avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 128px;
    height: 128px;
    line-height: 128px;
    text-align: center;
}
.avatar {
    width: 128px;
    height: 128px;
    display: block;
}
</style>
